<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
    <title>明细信息</title>
    <%@ include file="/resources/js/easyui/taglibs.jsp" %>
    <%@ include file="/resources/js/easyui/_easyui.jsp" %>
    <%@ include file="/resources/js/easyui/_message.jsp" %>
    <%@ include file="/resources/js/easyui/_viewJS.jsp" %>
</head>

<body class="easyui-layout">
<form id="addform">
    <table class="tableForm" style="width: 100%;">

        <tr>
            <th align="right" valign="top"><span class="redStart">*</span><label>商业编号：</label></th>
            <td><input name="merchantnumber" class="easyui-validatebox" value="${businessinfo.merchantnumber}"
                       placeholder="请输入商业编号" style="width:200px;" data-options="required:true"/></td>
        </tr>

        <tr>
            <th align="right" valign="top"><span class="redStart">*</span><label>商业密钥：</label></th>
            <td><input name="merchantkey" class="easyui-validatebox" value="${businessinfo.merchantkey}"
                       placeholder="请输入商业密钥" style="width:200px" data-options="required:true"/></td>
        </tr>

        <tr>
            <th align="right" valign="top"><span class="redStart">*</span><label>门店号：</label></th>
            <td><input name="shopnumber" class="easyui-validatebox" value="${businessinfo.text1}" name="shortcode"
                       placeholder="请输入支付宝门店号" style="width:200px" data-options="required:true"/></td>
        </tr>

        <tr>
            <th align="right" valign="top"><span class="redStart">*</span><label>费率：</label></th>
            <td><input name="rate" class="easyui-validatebox" value="${businessinfo.rate}" name="shortcode"
                       placeholder="请输入商业密钥" style="width:200px" data-options="required:true"/></td>
        </tr>
        <input type="hidden" name="userid" value="${businessinfo.userid}"/>
    </table>
</form>

<script type="application/javascript">

    function addBusinessInfo() {

        if ($("#addform").form('validate')) {
            $.ajax({
                url: '${basePath}web/giveinfo/saveUserBusinsessInfo',
                type: 'POST',
                data: $("#addform").serialize(),
                async: false,
                traditional: true,
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if (ret.result) {
                        $.messager.alert('温馨提示', ret.info, 'info');
                        parent.view.closeBusinessInfoWin(1);
                    } else {
                        $.messager.alert('温馨提示', ret.info, 'error');
                    }
                }
            });
        }
    }

    /* 验证手机号码、用户名或邮箱是否存在 */
    function validatorDataOnlien(value) {
        var result = true;
        $.ajax({
            url: '${basePath}web/childuser/vaildUserInfo',
            async: false,
            type: 'GET',
            data: {"vaildatorValue": value},
            traditional: true,
            success: function (ret) {
                result = ret.vaildatorResult;
            }
        });
        return result;
    }

    $.extend($.fn.validatebox.defaults.rules, {
        email: {
            validator: function (value, param) {
                if (/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)) {
                    if (validatorDataOnlien(value)) {

                        $.fn.validatebox.defaults.rules.email.message = '邮箱已经存在,请更换其他邮箱地址';
                        return false;
                    }
                } else {
                    $.fn.validatebox.defaults.rules.email.message = '请输入正确的邮箱地址';
                    return false;
                }
                return true;
            },
            message: ''
        },
        mobile: {
            validator: function (value, param) {
                if (/^(?:13\d|15\d|18\d|17\d|14\d)-?\d{5}(\d{3}|\*{3})$/.test(value)) {
                    if (validatorDataOnlien(value)) {

                        $.fn.validatebox.defaults.rules.mobile.message = '手机号码已经存在,请更换手机号码';
                        return false;
                    }
                } else {
                    $.fn.validatebox.defaults.rules.mobile.message = '请输入正确的手机号码';
                    return false;
                }
                return true;
            },
            message: ''
        },
        tel: {
            validator: function (value, param) {
                return /^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?(-\d{1,6})?$/.test(value);
            },
            message: '请输入正确的固话电话号码'
        },
        mobileAndTel: {
            validator: function (value, param) {
                return /(^([0\+]\d{2,3})\d{3,4}\-\d{3,8}$)|(^([0\+]\d{2,3})\d{3,4}\d{3,8}$)|(^([0\+]\d{2,3}){0,1}13\d{9}$)|(^\d{3,4}\d{3,8}$)|(^\d{3,4}\-\d{3,8}$)/.test(value);
            },
            message: '请输入正确的联系电话或手机号码'
        },
        username: {// 只能输入英文和数字和特殊字符
            validator: function (value, param) {
                /* return /^[a-zA-Z0-9_]{1,}$/.test(value); */
                if (/^[a-zA-Z0-9_]{1,}$/.test(value)) {
                    if (validatorDataOnlien(value)) {
                        $.fn.validatebox.defaults.rules.username.message = '用户名已经存在,请使用其他用户名';
                        return false;
                    }
                } else {
                    $.fn.validatebox.defaults.rules.username.message = '请输入英文、数字或下划线';
                    return false;
                }
                return true;
            },
            message: ''
        },
        passwordlegth: {
            validator: function (value) {
                return value.length >= 6;
            },
            message: '密码长度至少6位'
        },
        confirmPassword: {
            validator: function (value, param) {
                return value == $(param[0]).val();
            },
            message: '两次密码不一致'
        }
    });

</script>
</body>
</html>
